package models;

public class HandScore implements Comparable<HandScore>
	{
		public final static int HN_STRAIGHT_FLUSH 	= 8;
		public final static int HN_FOUR 			= 7;
		public final static int HN_FULL 			= 6;
		public final static int HN_FLUSH 			= 5;
		public final static int HN_STRAIGHT 		= 4;
		public final static int HN_THREE			= 3;
		public final static int HN_TWO_PAIR 		= 2;
		public final static int HN_ONE_PAIR 		= 1;
		public final static int HN_HIGH_CARD		= 0;
	
		int hand;
		int power;
		int power2;
		int kicker;
		int[] kickers;
		public Player player;
		
		public HandScore(Player pl, int h, int p)
		{
			player = pl;
			hand = h;
			power = p;
		}
		
		//wersja dla koloru i najwyzszej karty
		public HandScore(Player pl, int h, int[] k)
		{
			player = pl;
			hand = h;
			kickers = k;
		}
		
		//werja dla dwoch par
		public HandScore(Player pl, int h, int p, int p2, int k)
		{
			player = pl;
			hand = h;
			power = p;
			power2 = p2;
			kicker = k;
		}
		
		//wersja dla pary
		public HandScore(Player pl, int h, int p, int[] k)
		{
			player = pl;
			hand = h;
			power = p;
			kickers = k;
		}
		
		public int compareTo(HandScore h)
		{
			if(hand != h.hand) return hand - h.hand;
			else //remis
			switch(hand)
			{
				case HN_STRAIGHT_FLUSH: 	return power - h.power;
				case HN_FOUR: 				return power - h.power;
				case HN_FULL: 				return power - h.power;
				case HN_FLUSH: 				
											for(int i = 4; i>= 0; i--)
												if(kickers[i] != h.kickers[i])
													return kickers[i] - h.kickers[i];
											return 0;
				case HN_STRAIGHT:			return power - h.power;
				case HN_THREE:				return power - h.power;
				case HN_TWO_PAIR:			
											if(power != h.power) return power-h.power;
											if(power2 != h.power2) return power2-h.power2;
											if(kicker != h.kicker) return kicker-h.kicker;
											return 0;
				case HN_ONE_PAIR:			
											if(power != h.power) return power - h.power;
											for(int i = 2; i>=0; i--)
												if(kickers[i] != h.kickers[i])
													return kickers[i] - h.kickers[i];
											return 0;
				case HN_HIGH_CARD:			
											for(int i = 4; i>= 0; i--)
												if(kickers[i] != h.kickers[i])
													return kickers[i] - h.kickers[i];
											return 0;
 			}
			
			
			return 0;
		}
		
		public int getHand()
		{
			return hand;
		}
		
		public int getPower()
		{
			return power;
		}
		
	}